home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / graphics / qrt.lzh / PATTERNIO.C < prev    next >
C/C++ Source or Header  |  1989-02-16  |  6KB  |  266 lines

  1.  
  2. /**********************************************************
  3.  
  4.    This module loads patterns and sub-patterns for the
  5.    inout.c file, which was getting inconvienently big.
  6.  
  7.  **********************************************************/
  8.  
  9.  
  10. #include "qrt.h"
  11. #include "pattern.h"
  12.  
  13. char *Get_Next_Name();
  14. float Get_Next_Num(), IsPos();
  15.  
  16. /**********************************************************
  17.  
  18.      Attaches a pattern pointer to an object given
  19.      pattern name.
  20.  
  21.  **********************************************************/
  22.  
  23. PATTERN_PTR Attach_Pattern()
  24. {
  25.   char *patname;
  26.   PATTERN_PTR find_pat(), pat;
  27.  
  28.   patname=Get_Next_Name();
  29.   pat = find_pat(patname);
  30.   if (pat==NULL) Error(PATTERN_NOT_FOUND,1101);
  31.   free(patname);
  32.   return(pat);
  33. }
  34.  
  35.  
  36. /**********************************************************
  37.  
  38.    Load a circle sub-pattern and return pointer to it
  39.  
  40.  **********************************************************/
  41.  
  42. PATTERN_PTR Get_Circle_Pattern()
  43. {
  44.   char str[SLEN];
  45.   int end, f, found;
  46.   PATTERN_PTR pattern, new_pat();
  47.   CINFO cinfo;
  48.  
  49.   end=f=0;
  50.   pattern=new_pat();
  51.   pattern->type = CIRCLE_PATTERN;
  52.   def_colorinfo(&cinfo);
  53.  
  54.   GetLeftParen();
  55.  
  56.   while (!end && !feof(stdin)) {
  57.     GetToken(str); found = TRUE;
  58.  
  59.     if (strcmp(str,",")!=0) {
  60.       found = GetOpt(str,&cinfo);
  61.       if (strcmp(str,"RADIUS")==0) {
  62.         pattern->radius = IsPos(Get_Next_Num());
  63.         f|=1; found = TRUE;
  64.       }
  65.       if (strcmp(str,")")==0) { end=1; found = TRUE; }
  66.     }
  67.     if (!found) Error(UNDEFINED_PARAM,1102);
  68.  
  69.   }
  70.  
  71.   if (f!=1) Error(TOO_FEW_PARMS,1103);
  72.  
  73.   copy_colorinfo(&(pattern->cinfo),&cinfo);
  74.  
  75.   return(pattern);
  76. }
  77.  
  78. /**********************************************************
  79.  
  80.    Load a rectangle sub-pattern and return pointer to it
  81.  
  82.  **********************************************************/
  83.  
  84. PATTERN_PTR Get_Rect_Pattern()
  85. {
  86.   char str[SLEN];
  87.   int end, f, found;
  88.   PATTERN_PTR pattern, new_pat();
  89.   CINFO cinfo;
  90.  
  91.   end=f=0;
  92.   pattern=new_pat();
  93.   pattern->type = RECT_PATTERN;
  94.   def_colorinfo(&cinfo);
  95.  
  96.   GetLeftParen();
  97.  
  98.   while (!end && !feof(stdin)) {
  99.     GetToken(str); found = TRUE;
  100.  
  101.     if (strcmp(str,",")!=0) {
  102.       found = GetOpt(str,&cinfo);
  103.       if (strcmp(str,"START_X")==0) {
  104.         pattern->startx=Get_Next_Num();
  105.         f|=1; found = TRUE;
  106.       }
  107.       if (strcmp(str,"START_Y")==0) {
  108.         pattern->starty=Get_Next_Num();
  109.         f|=2; found = TRUE;
  110.       }
  111.       if (strcmp(str,"END_X")==0) {
  112.         pattern->endx=Get_Next_Num();
  113.         f|=4; found = TRUE;
  114.       }
  115.       if (strcmp(str,"END_Y")==0) {
  116.         pattern->endy=Get_Next_Num();
  117.         f|=8; found = TRUE;
  118.       }
  119.       if (strcmp(str,")")==0) { end=1; found = TRUE; }
  120.     }
  121.     if (!found) Error(UNDEFINED_PARAM,1104);
  122.  
  123.   }
  124.  
  125.   if (f!=15) Error(TOO_FEW_PARMS,1105);
  126.  
  127.   copy_colorinfo(&(pattern->cinfo),&cinfo);
  128.  
  129.   return(pattern);
  130. }
  131.  
  132. /**********************************************************
  133.  
  134.    Load a polygon sub-pattern and return pointer to it
  135.  
  136.  **********************************************************/
  137.  
  138. PATTERN_PTR Get_Poly_Pattern()
  139. {
  140.   char str[SLEN];
  141.   int end, f, found;
  142.   PATTERN_PTR pattern, pointpatt, new_pat();
  143.   CINFO cinfo;
  144.  
  145.   end=f=0;
  146.   pattern=new_pat();
  147.   pattern->type = POLY_PATTERN;
  148.   def_colorinfo(&cinfo);
  149.  
  150.   GetLeftParen();
  151.  
  152.   while (!end && !feof(stdin)) {
  153.     GetToken(str); found = TRUE;
  154.  
  155.     if (strcmp(str,",")!=0) {
  156.       found = GetOpt(str,&cinfo);
  157.       if (strcmp(str,"POINT")==0) {
  158.         GetLeftParen();
  159.  
  160.         pointpatt = new_pat();
  161.         pointpatt->startx = Get_Next_Num();
  162.         pointpatt->starty = Get_Next_Num();
  163.         f+=1; found = TRUE;
  164.         GetToken(str);
  165.  
  166.         if (strcmp(str,")") != 0) {
  167.           Error(RPAREN_EXPECTED,1106);
  168.         }
  169.  
  170.         str[0] = '\0';                 /* clear str */
  171.  
  172.         pointpatt->link = pattern->link;
  173.         pattern->link = pointpatt;
  174.       }
  175.       if (strcmp(str,")")==0) { end=1; found = TRUE; }
  176.     }
  177.     if (!found) Error(UNDEFINED_PARAM,1107);
  178.   }
  179.  
  180.   if (f<3) Error(TOO_FEW_PARMS,1108);
  181.  
  182.   copy_colorinfo(&(pattern->cinfo),&cinfo);
  183.  
  184.   return(pattern);
  185. }
  186.  
  187.  
  188. /**********************************************************
  189.  
  190.        Load a sub-pattern and return a pointer to it,
  191.        or null if not found.
  192.  
  193.  **********************************************************/
  194.  
  195. PATTERN_PTR Get_SubPattern(str)
  196.   char *str;
  197. {
  198.   if (strcmp(str,"RECTANGLE")==0)
  199.     return(Get_Rect_Pattern());
  200.  
  201.   if (strcmp(str,"CIRCLE")==0)
  202.     return(Get_Circle_Pattern());
  203.  
  204.   if (strcmp(str,"POLYGON")==0)
  205.     return(Get_Poly_Pattern());
  206.  
  207.   return(NULL);
  208. }
  209.  
  210.  
  211. /**********************************************************
  212.  
  213.         Load pattern and attach it to pattern list
  214.  
  215.  **********************************************************/
  216.  
  217. int GetPattern()
  218. {
  219.   char str[SLEN];
  220.   int end, f, found;
  221.   PATTERN_PTR pattern, spat, new_pat();
  222.  
  223.   end=f=0;
  224.   GetLeftParen();
  225.  
  226.   pattern = new_pat();
  227.  
  228.   pattern->type = PATT_HEADER;
  229.  
  230.   while (!end && !feof(stdin)) {
  231.     GetToken(str); found = TRUE;
  232.     if (strcmp(str,",")!=0) {
  233.       found = FALSE;
  234.       if (strcmp(str,"X_SIZE")==0) {
  235.          pattern->xsize=Get_Next_Num();
  236.          f|=1; found = TRUE;
  237.       }
  238.       if (strcmp(str,"Y_SIZE")==0) {
  239.          pattern->ysize=Get_Next_Num();
  240.          f|=2; found = TRUE;
  241.       }
  242.       if (strcmp(str,"NAME")==0) {
  243.          pattern->name=Get_Next_Name();
  244.          f|=4; found = TRUE;
  245.       }
  246.  
  247.       if ((spat=Get_SubPattern(str))!=NULL) {
  248.          spat->sibling=pattern->child;
  249.          pattern->child=spat;
  250.          f|=8; found = TRUE;
  251.       }
  252.       if (strcmp(str,")")==0) { end=1; found = TRUE; }
  253.     }
  254.     if (!found) Error(UNDEFINED_PARAM,1109);
  255.   }
  256.  
  257.   if (f!=15) Error(TOO_FEW_PARMS,1110);
  258.  
  259.   pattern->sibling=THEWORLD.patlist;
  260.   THEWORLD.patlist=pattern;
  261.  
  262.   return(TRUE);
  263. }
  264.  
  265.  
  266.